/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_Studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "构建几何节点.h"

#include <节点/容器节点/空间分割.h>
#include <节点/容器节点/数据缓存.h>
#include <节点/插座/list/list物体插座.h>
#include <节点/插座/list/list数值插座.h>
#include <节点/插座/list/list矢量插座.h>

#include <Context/当前默认操作数据.h>


#include "A_引擎/引擎.h"
#include "A_引擎/文件工程/工程文件.h"
#include "构建容器节点.h"



static void on_参数修改(S_Props& prop) {
	//switch ((*(S_PropValueEnum*)prop.m_Value).m_当前选项)
	auto nodes = f_global_get激活节点();
	for (auto 节点 : nodes) {
		节点->f_set是否要更新(true);

		for (auto& panel : 节点->m_包含在多个视口的UI部件) {
			C_节点面板* 节点面板 = static_cast<C_节点面板*>(panel);
			C_节点视口* view = static_cast<C_节点视口*>(节点面板->m_节点当前所在视口);
			节点面板->m_属性面板参数构建(view->m_属性栏, (S_结构对象指针)节点面板);
		}
	}
}

static void on_参数修改_打开对话框(S_Props& prop) {
	f_ui_set路径编辑框对话框类型(prop.m_UI->m_部件, E_对话框类型::e_读取);
	f_ui_set路径编辑框对话框后缀(prop.m_UI->m_部件, ".geom");
	if (f_ui_路径编辑框是否打开(prop.m_UI->m_部件)) {
		auto nodes = f_global_get激活节点();
		for (auto 节点 : nodes) {
			节点->f_set是否要更新(true);
		}
	}
}

static void on_网格缓存参数修改_打开对话框(S_Props& prop) {
	f_ui_set路径编辑框对话框类型(prop.m_UI->m_部件, E_对话框类型::e_打开路径);
	f_ui_set路径编辑框对话框后缀(prop.m_UI->m_部件, ".mesh");
	if (f_ui_路径编辑框是否打开(prop.m_UI->m_部件)) {
		auto nodes = f_global_get激活节点();
		for (auto 节点 : nodes) {
			节点->f_set是否要更新(true);
		}
	}
}



static void f_点距八叉树节点_3D视口更新(C_节点面板* node, S_Scene* scene) {
	C_点距八叉树节点* 节点 = dynamic_cast<C_点距八叉树节点*>(node->m_NodeData);
	//f_surface_创建实例((S_Mesh*)S_Core::g_当前独立显示物体->m_Data[3], 节点->m_GPU可视网格);
	S_框架::g_当前独显物体类型 = E_物体数据类型::e_八叉树;
	f_global_所在独显模型材质();

}

static void f_点距八叉树节点_部件构建属性(C_属性栏* plane, S_结构对象指针 obj) {
	C_点距八叉树节点* node = dynamic_cast<C_点距八叉树节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	//auto prop = f_alloc_F32Prop(DEF_F32插座数据(node->f_get输入插座(2), 0), L"最小范围半径");
	//props.push_back(prop);
	//prop = f_alloc_Vec3Prop(DEF_Vec3插座数据(node->f_get输入插座(3), 0), L"域大小");
	//prop.m_私有 = true;
	//props.push_back(prop);
	//prop = f_alloc_Vec3Prop(DEF_Vec3插座数据(node->f_get输入插座(4), 0), L"域偏移");
	//props.push_back(prop);

	plane->f_构建属性部件(props);

	//f_点距八叉树节点_3D视口更新(((C_节点面板*)obj), nullptr);

}

C_节点面板* f_节点构建_点距八叉树(S_UI创建环境& ctx, S_设备环境& dev_ctx, C_节点基类* node, C_节点面板* plane) {
	if (!node) node = new C_点距八叉树节点(dev_ctx);


	C_节点面板* nodeplane = f_节点创建_UI面板构建(ctx, node, E_节点区类型::e_节点区_物体);
	nodeplane->m_属性面板参数构建 = f_点距八叉树节点_部件构建属性;
	nodeplane->m_3D视口更新 = f_点距八叉树节点_3D视口更新;
	nodeplane->m_ICO = "ico八叉树0004";

	return nodeplane;
}

void f_节点重置_点距八叉树(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板重构(plane, node, E_节点区类型::e_节点区_物体);
	f_节点重构_插座重构(plane, node, E_节点区类型::e_节点区_物体);

	plane->m_属性面板参数构建 = f_点距八叉树节点_部件构建属性;
	plane->m_ICO = "ico八叉树0004";
}







static void f_数据缓存写入_部件构建属性(C_属性栏* plane, S_结构对象指针 obj) {
	C_数据缓存写入节点* node = dynamic_cast<C_数据缓存写入节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	props.push_back(node->m_Path);
	//props.push_back(node->m_方式);
	props.push_back(node->m_格式);
	props.push_back(node->m_文件名);

	plane->f_构建属性部件(props);

}

C_节点面板* f_节点构建_数据缓存写入(S_UI创建环境& ctx, S_设备环境& dev_ctx, C_节点基类* node, C_节点面板* plane) {
	if (!node) node = new C_数据缓存写入节点(dev_ctx);

	if (plane == nullptr) {
		plane = f_节点创建_UI面板构建(ctx, node, E_节点区类型::e_节点区_物体);
	}
	f_节点重置_数据缓存写入(plane, node);

	return plane;
}

void f_节点重置_数据缓存写入(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板重构(plane, node, E_节点区类型::e_节点区_物体);
	f_节点重构_插座重构(plane, node, E_节点区类型::e_节点区_物体);

	plane->m_属性面板参数构建 = f_数据缓存写入_部件构建属性;
	plane->m_ICO = "ico_缓存文件0019";
}




static void f_数据缓存读取_部件构建属性(C_属性栏* plane, S_结构对象指针 obj) {
	C_数据缓存读取节点* node = dynamic_cast<C_数据缓存读取节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	props.push_back(node->m_Path);
	//props.push_back(node->m_方式);
	props.push_back(node->m_格式);
	props.push_back(node->m_文件名);

	plane->f_构建属性部件(props);

}

C_节点面板* f_节点构建_数据缓存读取(S_UI创建环境& ctx, S_设备环境& dev_ctx, C_节点基类* node, C_节点面板* plane)
{
	if (!node) node = new C_数据缓存读取节点(dev_ctx);

	if (plane == nullptr) {
		plane = f_节点创建_UI面板构建(ctx, node, E_节点区类型::e_节点区_物体);
	}
	f_节点重置_数据缓存读取(plane, node);

	return plane;
}

void f_节点重置_数据缓存读取(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板重构(plane, node, E_节点区类型::e_节点区_物体);
	f_节点重构_插座重构(plane, node, E_节点区类型::e_节点区_物体);

	plane->m_属性面板参数构建 = f_数据缓存读取_部件构建属性;
	plane->m_ICO = "ico_缓存文件读取0020";
}





static void f_物体缓存节点_部件构建属性(C_属性栏* plane, S_结构对象指针 obj) {
	C_物体缓存节点* node = dynamic_cast<C_物体缓存节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	node->m_Path.m_UI->m_Update = on_参数修改_打开对话框;
	props.push_back(node->m_Path);

	node->m_类型.m_UI->m_Update = on_参数修改;
	props.push_back(node->m_类型);

	node->m_应用变换.m_UI->m_Update = on_参数修改;
	props.push_back(node->m_应用变换);
	if (f_prop_Bool(node->m_应用变换)) {
		node->m_中心变换方式.m_UI->m_Update = on_参数修改;
		props.push_back(node->m_中心变换方式);
	}
	
	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_物体缓存(S_UI创建环境& ctx, S_设备环境& ctx_3d, C_节点基类* node, C_节点树* tree) {
	if (!node) {
		node = new C_物体缓存节点(ctx_3d);
		node->m_ICO = "ico_缓存文件0019";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_物体缓存(plane, node);
	return plane;
}

void f_节点重置_物体缓存(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板重构(plane, node, E_节点区类型::e_节点区_物体);
	f_节点重构_插座重构(plane, node, E_节点区类型::e_节点区_物体);

	plane->m_属性面板参数构建 = f_物体缓存节点_部件构建属性;
	plane->m_ICO = node->m_ICO;
}




static void f_网格缓存写入节点_部件构建属性(C_属性栏* plane, S_结构对象指针 obj) {
	C_网格缓存写入节点* node = dynamic_cast<C_网格缓存写入节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	node->m_Path.m_UI->m_Update = on_网格缓存参数修改_打开对话框;
	props.push_back(node->m_Path);

	node->m_文件名称.m_UI->m_Update = on_参数修改;
	props.push_back(node->m_文件名称);

	node->m_覆盖文件.m_UI->m_Update = on_参数修改;
	props.push_back(node->m_覆盖文件);

	node->m_序列文件.m_UI->m_Update = on_参数修改;
	props.push_back(node->m_序列文件);

	node->m_元素.m_UI->m_Update = on_参数修改;
	props.push_back(node->m_元素);
	
	node->m_应用变换.m_UI->m_Update = on_参数修改;
	props.push_back(node->m_应用变换);
	
	node->m_中心变换方式.m_UI->m_Update = on_参数修改;
	props.push_back(node->m_中心变换方式);

	node->m_压缩.m_UI->m_Update = on_参数修改;
	props.push_back(node->m_压缩);

	node->m_压缩等级.m_UI->m_Update = on_参数修改;
	props.push_back(node->m_压缩等级);

	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_网格缓存写入(S_UI创建环境& ctx, S_设备环境& ctx_3d, C_节点基类* node, C_节点树* tree) {
	if (!node) {
		node = new C_网格缓存写入节点(ctx_3d);
		node->m_ICO = "ico_缓存文件0019";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_网格缓存写入(plane, node);
	return plane;
}

void f_节点重置_网格缓存写入(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_物体);
	plane->m_属性面板参数构建 = f_网格缓存写入节点_部件构建属性;
	plane->m_ICO = node->m_ICO;
}




static void f_读取网格缓存节点_部件构建属性(C_属性栏* plane, S_结构对象指针 obj) {
	C_读取网格缓存节点* node = dynamic_cast<C_读取网格缓存节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	node->m_Path.m_UI->m_Update = on_网格缓存参数修改_打开对话框;
	props.push_back(node->m_Path);

	node->m_文件名称.m_UI->m_Update = on_参数修改;
	props.push_back(node->m_文件名称);

	node->m_序列文件.m_UI->m_Update = on_参数修改;
	props.push_back(node->m_序列文件);

	node->m_循环区间.m_UI->m_Update = on_参数修改;
	props.push_back(node->m_循环区间);

	node->m_元素.m_UI->m_Update = on_参数修改;
	props.push_back(node->m_元素);

	node->m_应用变换.m_UI->m_Update = on_参数修改;
	props.push_back(node->m_应用变换);

	node->m_中心变换方式.m_UI->m_Update = on_参数修改;
	props.push_back(node->m_中心变换方式);

	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_读取网格缓存(S_UI创建环境& ctx, S_设备环境& ctx_3d, C_节点基类* node, C_节点树* tree) {
	if (!node) {
		node = new C_读取网格缓存节点(ctx_3d);
		node->m_ICO = "ico_缓存文件读取0020";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_读取网格缓存(plane, node);
	return plane;
}

void f_节点重置_读取网格缓存(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_物体);
	plane->m_属性面板参数构建 = f_读取网格缓存节点_部件构建属性;
	plane->m_ICO = node->m_ICO;
}

















